package week8;

/**
 * Created by Administrator on 2016/4/23.
 */
import java.util.Scanner;
import java.lang.String;

public class Code {
    public static void main(String[] args) {
        int i = 0;
        int k = 0;

        //输入密钥


        do {
            System.out.println("请输入密钥(1~25)：");
            Scanner miyao = new Scanner(System.in);
            k = miyao.nextInt();
        }while ( k > 25);

        //输入明文


        System.out.println("请输入明文：");
        Scanner mingwen = new Scanner(System.in);
        String m = mingwen.nextLine();
        char[] mm = m.toCharArray();

        //加密过程


        for(i = 0;i < m.length();i++) {
            if(mm[i] > 96 && mm[i] < 123 ) {
                mm[i] += k;
                if(mm[i] > 123) {
                    mm[i] -= 26;
                }
            }
            if(mm[i] > 64 && mm[i] < 91) {
                mm[i] += k;
                if(mm[i] > 91) {
                    mm[i] -= 26;
                }
            }
        }

        //输出密文


        System.out.println("输出密文是：");
        for(i = 0; i < m.length(); i++) {
            System.out.print(mm[i]);
        }
    }
}
